package com.lixinyue.test03;

/**
 * @program: 11.12
 * @description:
 * @author: 李鑫月
 * @create: 2021-11-12 17:50
 **/
class Animal{
    public String name;
    public  int age;
    protected int count;
    public Animal(String name,int age){
        this.name=name;
        this.age=age;
    }

    public void  eat(){
        System.out.println(this.name+" is eating");
    }
}
class Dog extends Animal {
    public Dog(String name,int age){
        super(name,age);//显式调用构造方法，调用父类调用两个参数的构造方法
    }
    //默认的构造方法
//    public Dog(){
//        super();//显式调用构造方法，调用父类调用两个参数的构造方法
//    }
    @Override
    public void eat(){
        System.out.println(name+" 狼吞虎咽的eat（）");
    }

}

class Bird extends Animal {
    public String wing;
    public String name="qqq";
    public Bird(String name,int age,String wing){
        super(name,age);
        this.wing=wing;
    }
    public void  fly(){
        System.out.println(super.name+super.age+" 岁 "+"is flying");
    }
}
class Red extends Bird {
    public int colo;

    public Red(String name, int age,String wing) {
        super(name, age,wing);
    }
}



public class Test {
    public static void func(Animal ani){
        ani.eat();
    }
    public static Animal func2(){
        Dog dog=new Dog("lixinyue",23);
        return dog;
    }

    public static void main(String[] args) {
        Animal animal1=new Dog("wer",33);
        animal1.eat();
    }

    public static void main3(String[] args) {
        Animal animal=new Bird("zy",11,"chibang");

        if(animal instanceof Bird){
            Bird bird=(Bird)animal;
            bird.fly();
        }
        Animal animal1=new Dog("wer",33);


    }
    public static void main2(String[] args) {
        Bird bird=new Bird("zzz",12,"小翅膀");
        System.out.println(bird.name);//打印的是子类的姓名
        Animal animal1=new Bird("lxy",10,"大翅膀");
        animal1.eat();

        System.out.println(animal1.name);//打印的是父类的姓名  why???
        //System.out.println(animal1.swing);//虽然父类引用 引用子类对象，但不能访问子类独有的属性



    }
    public static void main1(String[] args) {
    Animal animal1=new Dog("zqw",10);//父类引用 引用子类对象
        Dog dog=new Dog("zqw",10);
 //       dog.eat();
   //  func(dog);
//        Animal ani=func2();
//        ani.eat();
        Animal animal=new Dog("lixinru",101);
        animal.eat();
    }
}
